﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Class_Entity;
using BussinessObject;
using System.Data;
using System.Data.SqlClient;

public partial class WebApplication_ADAddAccounts : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["RoleCode"] != null)
        {
            if (Convert.ToInt32((Session["Rolecode"].ToString())) == 3)
            {
                Response.Redirect("ADResume.aspx");
            }
        }
        else
            Response.Redirect("Login.aspx");
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        BOUsers bus = new BOUsers();
        Users us = new Users();
        us.Username = txtName.Text.Trim();
        us.Password = txtPass.Text.Trim();
        us.Email = txtEmail.Text.Trim();
        us.RoleCode = Convert.ToInt32(DropDownList1.SelectedItem.Value);

        if (Session["b"] == null)
        {
            bus.Add_Admins(us);
            HttpContext.Current.Response.Write("<script type='text/javascript'>alert('" + "Add new Account Successfully ..." + "');window.location.href='ADAccounts.aspx';</script>");
        }
    }
    protected void txtName_TextChanged(object sender, EventArgs e)
    {
        BOUsers bo = new BOUsers();
        Users us = new Users();
        DataTable dt = bo.Load_Users(us).Tables[0];
        Label1.Text = "";
        Session["b"] = null;
        txtPass.Focus();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if (txtName.Text.Trim() == dt.Rows[i][1].ToString())
            {
                Session["b"] = 1;
                Label1.Text = "Invalid Name";
            }

        }
    }
}